<?php
/*
+-----------------------------------------------------------------------------+
| $Id: *.php 2009-08-18 08:41:22Z Bleakwind $
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
+-----------------------------------------------------------------------------+
*/

if (!defined( 'ENTRY_INDEX')){
    echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
    exit;
}

// friendlink_list
$where          = "";
$where_total    = "";

$where          .= " AND ((friendlink.if_enable=1) || (friendlink.if_enable=3 AND friendlink.if_enable_begin<".$sys->nowtime." AND friendlink.if_enable_end>".$sys->nowtime."))";
$where_total    .= " AND ((if_enable=1) || (if_enable=3 AND if_enable_begin<".$sys->nowtime." AND if_enable_end>".$sys->nowtime."))";

$where       = substr(trim($where), 0, 3) == "AND" ? substr(trim($where), 3) : trim($where);
$where_total = substr(trim($where_total), 0, 3) == "AND" ? substr(trim($where_total), 3) : trim($where_total);
$where       = $where != "" ? "WHERE ".$where : "";
$where_total = $where_total != "" ? "WHERE ".$where_total : "";

$total_record = 0;
$sql = "SELECT count(*) as total_record
        FROM ".DB_TABLE_FRIENDLINK."
        ".$where_total;
$result = &$db->Execute($sql);
if ($result) {
    $total_record = (int)$result->fields['total_record'];
}
$bwpage->set_record_listnum($CONFIG['page_record_friendlink_list']);
$bwpage->set_record($total_record);
$bwpage->page($CONFIGURE['common']['control_index']."?act=friendlink_list&pag=%s");
$sql = "SELECT friendlink.*,
            cover.id as cover_id, cover.dir as cover_dir, cover.filename as cover_filename
        FROM ".DB_TABLE_FRIENDLINK." friendlink
            LEFT JOIN ".DB_TABLE_FRIENDLINK_COVER." cover ON cover.friendlink_id=friendlink.id
        ".$where."
        ORDER BY friendlink.if_top DESC, friendlink.rank, friendlink.post_time DESC
        LIMIT ".$bwpage->record_listfirst.",".$bwpage->record_listnum;
$result = &$db->Execute($sql);
if (!$result) {
    echo $db->ErrorMsg();
} else {
    while (!$result->EOF) {
        $friendlink_list[] = array(
            'id'                    => $result->fields['id'],
            'phrase'                => $result->fields['phrase'],
            'phrase_len'            => mb_strwidth($result->fields['phrase'],"UTF-8"),
            'subject'               => $result->fields['subject'],
            'subject_len'           => mb_strwidth($result->fields['subject'],"UTF-8"),
            'prefix'                => $result->fields['prefix'],
            'color'                 => $result->fields['color'],
            'fontstyle'             => $result->fields['fontstyle'],
            'decoration'            => $result->fields['decoration'],
            'keyword'               => $result->fields['keyword'],
            'brief'                 => $result->fields['brief'],
            'post_id'               => $result->fields['post_id'],
            'post_username'         => $result->fields['post_username'],
            'post_ip'               => $result->fields['post_ip'],
            'post_time'             => $result->fields['post_time'],
            'amend_id'              => $result->fields['amend_id'],
            'amend_username'        => $result->fields['amend_username'],
            'amend_ip'              => $result->fields['amend_ip'],
            'amend_time'            => $result->fields['amend_time'],
            'click'                 => $result->fields['click'],
            'if_enable'             => $result->fields['if_enable'],
            'if_enable_begin'       => $result->fields['if_enable_begin'],
            'if_enable_end'         => $result->fields['if_enable_end'],
            'if_top'                => $result->fields['if_top'],
            'if_top_begin'          => $result->fields['if_top_begin'],
            'if_top_end'            => $result->fields['if_top_end'],
            'if_turn'               => $result->fields['if_turn'],
            'if_turn_url'           => $result->fields['if_turn_url'],
            'rank'                  => $result->fields['rank'],

            'cover_id'              => $result->fields['cover_id'],
            'cover_dir'             => $result->fields['cover_dir'],
            'cover_filename'        => $result->fields['cover_filename'],
        );
        $result->MoveNext();
    }
}
$t->assign(array(
    "friendlink_list"  => $friendlink_list,
    "pagination"    => $bwpage->pagination,
));
//////
$public_var['page_place'][] = $LANGUAGE['s']['friendlink_list']['page_place'];
?>
